/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ball;

// doi lai la tao ne

import java.util.Scanner;
// sua chua
public class Main {

    Scanner kk = new Scanner(System.in);
    int n, m;
    // private boolean dao;

    void sinhmang(int a[]) {
        System.out.print("\n nhap n = ");
        n = kk.nextInt();
        m = n * 2 + 1;
        for (int i = 0; i < n; i++) {
            a[i] = 1;
        }
        for (int j = n; j < m; j++) {
            a[j] = 2;
        }
        a[n] = 0;
    }

    void xuat(int a[]) {
        for (int i = 0; i < n; i++) {
            System.out.print(a[i] + " ");
        }
        //System.out.print(a[n]);
        for (int j = n; j < m; j++) {
            System.out.print(a[j]+" ");
        }
    }

    boolean kiemTraDao(int a[], int n) {
        for (int i = 0; i <= n; i++) {
            if (a[i] == 1) {
                return false;
            }
        }
        return true;
    }

    void hoanvi(int a, int b) {
        int temp = a;
        a = b;
        b = temp;
    }

    void xuly1(int a[]) {
        int i = n - 1;
        m=2*n+1;
        int temp;
        while (!kiemTraDao(a, n)) {
            switch (a[i]) {
                case 1: {
                    if (a[i+1]==0) //&& i<=n)
                    {
                    	temp =a[i];
                    	a[i]=a[i+1];
                    	a[i+1]=temp;
                    	i=i+2;
                    	System.out.print("\n");xuat(a);
                    }
                    else if(a[i+2]==0&& i+2<m-1)
                    {
                    	temp=a[i];
                    	a[i]=a[i+2];
                    	a[i+2]=temp;
                    	//i=i-2;
                    	System.out.print("\n");xuat(a);
                    	//if(i!=0 && i-2<0 &&a[i-1]==a[i+1])
                    	//	i=1;
                    	//else
                    	//{
                    		i=i-2;
                    	//	if(i<0) i=0;
                    	//}
                    }
                    else if(a[i-1]==0)
                    {
                    	temp=a[i-1];
                    	a[i-1]=a[i+1];
                    	a[i+1]=temp;
                    	i=i+2;
                    	System.out.print("\n");xuat(a);
                    	if(i>m-1)i=i-2;
                    }
                    /*else if(a[i+1]==0 &&i>n){
                    	temp=a[i];
                    	a[i]=a[i+1];
                    	a[i+1]=temp;
                    	i=i-2;System.out.print("\n");xuat(a);
                    }*/
                    break;
                }
                case 2: {
                	if(a[i-1]==0)//&& i>n)
                    {
                    	temp=a[i];
                    	a[i]=a[i-1];
                    	a[i-1]=temp;
                    	i=i-2;
                    	System.out.print("\n");xuat(a);
                    }
                    else if(a[i-2]==0)
                    {
                    	temp=a[i];
                    	a[i]=a[i-2];
                    	a[i-2]=temp;
                    	i=i+1;
                    	System.out.print("\n");xuat(a);
                    	if(i>=m) i=i-2;
                    }
                    /*else if(a[i+1]==0 &&i>n){
                    	temp=a[i];
                    	a[i]=a[i+1];
                    	a[i+1]=temp;
                    	i=i-2;System.out.print("\n");xuat(a);
                    }*/

                }break;
                case 0:{
                	if(a[i+1]==2 && a[i+2]!=a[i+1])
                	{
                		temp=a[i];
                		a[i]=a[i+1];
                		a[i+1]=temp;
                		i++;
                		System.out.print("\n");xuat(a);
                	}
                	else if(a[i+1]==1&& a[i+2]!=a[i+1])
                	{
                		temp=a[i];
                		a[i]=a[i+2];
                		a[i+2]=temp;
                		i++;
                		System.out.print("\n");xuat(a);
                	}break;
                }
            }
        }
    }
  //  public int tinh(int a,int b)
   // {
   //     return (a+b);
   / //}

    public static void main(String args[])
    {
    	Main x=new Main();
    	int []a= new int [10];
    	x.sinhmang(a);
    	x.xuly1(a);
    	//System.out.print("n= "); n=k.next

    }
}
